import NftEggsNFT from "../contracts/NftEggsNFT.cdc"
import NftEggsStore from "../contracts/NftEggsStore.cdc"

//初始化帐户以交易NFT
transaction {

    prepare(signer: AuthAccount) {

        // 检查账户是否已经初始化NFT
        if signer.borrow<&NftEggsNFT.Collection>(from: /storage/NFTCollection) == nil {
			// 创建一个空集合
			let collection <- NftEggsNFT.createEmptyCollection()

			// 保存到账户
			signer.save(<-collection, to: /storage/NFTCollection)

			// 为集合创建公共功能
			signer.link<&{NftEggsNFT.NftEggsNFTCollectionPublic}>(
				/public/NFTCollection,
				target: /storage/NFTCollection
			)
        }

		
		// 检查账户是否已经初始化NFT市场
        if signer.borrow<&NftEggsStore.Storefront>(from: NftEggsStore.StorefrontStoragePath) == nil {

            // 创建一个空的Storefront
            let storefront <- NftEggsStore.createStorefront() as! @NftEggsStore.Storefront
            
            // 保存到账户
            signer.save(<-storefront, to: NftEggsStore.StorefrontStoragePath)

            // 为Storefront创建公共功能
            signer.link<&NftEggsStore.Storefront{NftEggsStore.StorefrontPublic}>(
				NftEggsStore.StorefrontPublicPath,
				target: NftEggsStore.StorefrontStoragePath
			)
        }
		

		
	}
}
